package com.kjj.car.es.doc;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;

@Data
@Document(indexName = "kjj-car",type = "car")
public class CarDoc {
    @Id
    private Long id;
    @Field(type = FieldType.Text, analyzer = "ik_smart"
            , searchAnalyzer = "ik_smart")
    private String title;
    @Field(type = FieldType.Keyword)
    private String cover;
    @Field(type = FieldType.Double)
    private BigDecimal saleprice;
    @Field(type = FieldType.Double)
    private BigDecimal costprice;
    @Field(type = FieldType.Integer)
    private Integer isnew;
    @Field(type = FieldType.Date)
    @JsonFormat(pattern="yyyy-MM",timezone="GMT+8")//get
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date reigstertime;
    @Field(type = FieldType.Double)
    private Double mileage;
    @Field(type = FieldType.Long)
    private Long shopId;
    @Field(type = FieldType.Text, analyzer = "ik_smart"
            , searchAnalyzer = "ik_smart")
    private String shopName;

    @Field(type = FieldType.Keyword)
    private String shopAdress;
    @Field(type = FieldType.Date)
    private Date onsaletime;
    @Field(type = FieldType.Integer)
    private Integer costeffective;
    @Field(type = FieldType.Integer)
    private Integer rushsale;
    @Field(type = FieldType.Integer)
    private Integer quasinewcar;
    @Field(type = FieldType.Integer)
    private Integer transitivecountry;
    @Field(type = FieldType.Long)
    private Long typeId;
    @Field(type = FieldType.Text, analyzer = "ik_smart"
            , searchAnalyzer = "ik_smart")
    private String typeName;
    @Field(type = FieldType.Text, analyzer = "ik_smart"
            , searchAnalyzer = "ik_smart")
    private String carInfo;
    public String getShopAdress() {
        String shopAdress1 = shopAdress.substring(0,shopAdress.indexOf("区")+1);
        if (shopAdress1 != null) {
            return shopAdress1;
        }
        return shopAdress.substring(0,shopAdress.indexOf("县")+1);
    }
    public void setShopAdress(String shopAdress) {
        this.shopAdress = shopAdress;
    }

}
